home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Tools
/
Packer
/
xad
/
Developer
/
Sources
/
tools
/
xadUnFile.c
< prev
Wrap
C/C++ Source or Header
|
1999-11-06
|
11KB
|
370 lines
#define NAME "xadUnFile"
#define DISTRIBUTION "(Freeware) "
#define REVISION "1"
/* Programmheader
Name: xadUnFile
Author: SDI
Distribution: Freeware
Description: dearchives file archives
Compileropts: -
Linkeropts: -gsi -l amiga
1.0 13.09.98 : first version
1.1 18.11.98 : added FILE parameter and directory creation
*/
#include <proto/xadmaster.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <exec/memory.h>
#include <dos/dosasl.h>
#include <utility/hooks.h>
#include "SDI_defines.h"
#include "SDI_compiler.h"
#define SDI_TO_ANSI
#include "SDI_ASM_STD_protos.h"
#ifdef __SASC
#define xadmasterbase xadMasterBase
#define ASSIGN_XAD
#else
struct xadMasterBase * xadMasterBase = 0;
#define ASSIGN_XAD xadMasterBase = xadmasterbase;
#endif
struct DosLibrary * DOSBase = 0;
struct ExecBase * SysBase = 0;
#define PARAM "FROM/A,DESTDIR,PASSWORD/K,FILE/M,NE=NOEXTERN/S," \
"INFO=LIST/S,OW=OVERWRITE/S,NOTREE/S,ASKMAKEDIR/S," \
"NOCOMMENT/S,NOPROT/S,NODATE/S"
#define OPTIONS \
"FROM The input archive file (no patterns allowed)\n" \
"DESTDIR The destination directory, not needed with INFO\n" \
"PASSWORD A password for encrypted archives\n" \
"FILE Multiple filenames (with patterns) to be extracted\n" \
"NOEXTERN Turns off usage of external clients\n" \
"INFO Shows archive information without extracting\n" \
"OVERWRITE Files are overwritten without asking\n" \
"NOTREE Files are extracted without subdirectories\n" \
"ASKMAKEDIR You get asked before a directory is created\n" \
"NOCOMMENT No filenote comments are extracted\n" \
"NOPROT Protection information gets not extracted\n" \
"NODATE Creation date information gets not extracted\n" \
struct xHookArgs {
STRPTR name;
ULONG flags;
};
struct Args {
STRPTR from;
STRPTR destdir;
STRPTR password;
STRPTR * file;
ULONG noextern;
ULONG info;
ULONG overwrite;
ULONG notree;
ULONG askmakedir;
ULONG nocomment;
ULONG noprot;
ULONG nodate;
};
ASM(ULONG) progrhook(REG(a0, struct Hook *),
REG(a1, struct xadProgressInfo *));
LONG CheckName(STRPTR *pat, STRPTR name);
ULONG start(void)
{
ULONG ret = RETURN_FAIL;
struct DosLibrary *dosbase;
SysBase = (*((struct ExecBase **) 4));
{ /* test for WB and reply startup-message */
struct Process *task;
if(!(task = (struct Process *) FindTask(0))->pr_CLI)
{
WaitPort(&task->pr_MsgPort);
Forbid();
ReplyMsg(GetMsg(&task->pr_MsgPort));
return RETURN_FAIL;
}
}
if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
{
LONG err = 0;
struct xadMasterBase *xadmasterbase;
DOSBase = dosbase;
if((xadmasterbase = (struct xadMasterBase *)
OpenLibrary("xadmaster.library", 1)))
{
struct Args args;
struct RDArgs *rda;
memset(&args, 0, sizeof(struct Args));
ASSIGN_XAD
if((rda = (struct RDArgs *) AllocDosObject(DOS_RDARGS, 0)))
{
rda->RDA_ExtHelp = OPTIONS;
if(ReadArgs(PARAM, (LONG *) &args, rda))
{
if(args.destdir || args.info)
{
struct xadArchiveInfo *ai;
if((ai = (struct xadArchiveInfo *)
xadAllocObjectA(XADOBJ_ARCHIVEINFO, 0)))
{
if(!(err = xadGetInfo(ai, XAD_INFILENAME, args.from,
XAD_NOEXTERN, args.noextern, args.password ? XAD_PASSWORD :
TAG_IGNORE, args.password, TAG_DONE)))
{
if(args.info)
{
struct xadFileInfo *xfi;
Printf("ArchiverName: %s\n"
"Size CrndSize Date Time Name\n",
ai->xai_Client->xc_ArchiverName);
xfi = ai->xai_FileInfo;
while(xfi && !CTRL_C)
{
if(xfi->xfi_Flags & XADFIF_DIRECTORY)
{
if(!args.notree)
Printf(" <dir> <dir> %02ld.%02ld.%04ld %02ld:%02ld:%02ld %s\n",
xfi->xfi_Date.xd_Day, xfi->xfi_Date.xd_Month,
xfi->xfi_Date.xd_Year, xfi->xfi_Date.xd_Hour,
xfi->xfi_Date.xd_Minute, xfi->xfi_Date.xd_Second,
xfi->xfi_FileName);
}
else
Printf("%8ld %8ld %02ld.%02ld.%04ld %02ld:%02ld:%02ld %s\n",
xfi->xfi_Size, xfi->xfi_CrunchSize,
xfi->xfi_Date.xd_Day, xfi->xfi_Date.xd_Month,
xfi->xfi_Date.xd_Year, xfi->xfi_Date.xd_Hour,
xfi->xfi_Date.xd_Minute, xfi->xfi_Date.xd_Second,
args.notree ? FilePart(xfi->xfi_FileName) :
xfi->xfi_FileName);
#ifdef DEBUG
if(xfi->xfi_Flags)
{
Printf("Flags: ");
if(xfi->xfi_Flags & XADFIF_CRYPTED)
Printf("XADFIF_CRYPTED ");
if(xfi->xfi_Flags & XADFIF_DIRECTORY)
Printf("XADFIF_DIRECTORY ");
if(xfi->xfi_Flags & XADFIF_LINK)
Printf("XADFIF_LINK ");
if(xfi->xfi_Flags & XADFIF_INFOTEXT)
Printf("XADFIF_INFOTEXT ");
if(xfi->xfi_Flags & XADFIF_GROUPED)
Printf("XADFIF_GROUPED ");
if(xfi->xfi_Flags & XADFIF_ENDOFGROUP)
Printf("XADFIF_ENDOFGROUP ");
Printf("\n");
}
#endif
if(xfi->xfi_Flags & XADFIF_CRYPTED)
Printf("The entry is encrypted\n");
xfi = xfi->xfi_Next;
}
ret = 0;
}
else
{
struct Hook prhook;
struct xadFileInfo *fi;
UBYTE filename[256];
struct xHookArgs xh;
xh.name = filename;
xh.flags = 0;
memset(&prhook, 0, sizeof(struct Hook));
prhook.h_Entry = (ULONG (*)()) progrhook;
prhook.h_Data = &xh;
fi = ai->xai_FileInfo;
while(!err && fi)
{
if(!args.file || CheckName(args.file, args.notree ?
FilePart(fi->xfi_FileName) : fi->xfi_FileName))
{
CopyMem(args.destdir, filename, strlen(args.destdir)+1);
AddPart(filename, args.notree ? FilePart(fi->xfi_FileName) :
fi->xfi_FileName, 256);
if(fi->xfi_Flags == XADFIF_DIRECTORY)
{
if(!args.notree)
{
BPTR a;
LONG err = 0, i = 0;
UBYTE r;
while(filename[i] && !err)
{
for(;filename[i] && filename[i] != '/'; ++i)
;
r = filename[i];
filename[i] = 0;
if((a = Lock(filename, SHARED_LOCK)))
UnLock(a);
else if((a = CreateDir(filename)))
UnLock(a);
else
err = 1;
filename[i++] = r;
}
if(err)
Printf("failed to create directory '%s'\n",
fi->xfi_FileName);
else
Printf("Created directory : %s\n", filename);
}
}
else if(fi->xfi_Flags & XADFIF_LINK)
{
Printf("Skipped Link\n");
}
else
{
struct DateStamp d;
if((err = xadFileUnArc(ai, XAD_OUTFILENAME, filename,
XAD_ENTRYNUMBER, fi->xfi_EntryNumber, XAD_MAKEDIRECTORY,
!args.askmakedir, XAD_OVERWRITE, args.overwrite,
XAD_PROGRESSHOOK, &prhook, TAG_DONE)) == XADERR_SKIP)
err = 0;
else if(!err)
{
if(!args.nodate && !xadConvertDates(XAD_DATEXADDATE,
&fi->xfi_Date, XAD_GETDATEDATESTAMP, &d, TAG_DONE))
SetFileDate(filename, &d);
if(!args.noprot)
SetProtection(filename, fi->xfi_Protection);
if(fi->xfi_Comment && !args.nocomment)
SetComment(filename, fi->xfi_Comment);
/* SetOwner ??? */
}
}
}
fi = fi->xfi_Next;
}
if(!err)
ret = 0;
}
xadFreeInfo(ai);
} /* xadGetInfo */
xadFreeObjectA(ai, 0);
} /* xadAllocObject